import logging.handlers

import config.path_cfg as cfg


def init_logging():
    # 日志器
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)

    # 处理器
    # sh = logging.StreamHandler()
    fh = logging.handlers.TimedRotatingFileHandler(cfg.BASE_DIR + '/log/p2p_log.log',
                                                   when='midnight',
                                                   interval=1,
                                                   backupCount=2,
                                                   encoding='utf-8')

    # 格式器
    fmt = "%(asctime)s %(levelname)s [%(filename)s(%(funcName)s:%(lineno)d)] - %(message)s"

    formatter = logging.Formatter(fmt)

    # sh.setFormatter(formatter)
    fh.setFormatter(formatter)
    logger.addHandler(fh)
